# zero_axis.py

from __future__ import division

from ot_simulator.transform import transform
from ot_simulator.component import component

class zero_axis(component.component):
    r'''This zeroes one axis.

    ===============  =====================================================
     Input setting   
    ===============  =====================================================
    axis             which axis to zero, 'X', 'Y' or 'Z'.  No default.
    ===============  =====================================================

    ===============  ==========================
    Output setting
    ===============  ==========================
    <none>
    ===============  ==========================
    '''
    input_parameters = ('axis',)

    def get_transform(self, params, transform_in):
        # get translations
        x, y, z = transform_in.local_to_global()

        axis_param = self.get_param(params, 'axis')
        axis = axis_param.upper()
        if axis == 'X':
            offset_transform = transform.translation(x = -x)
        elif axis == 'Y':
            offset_transform = transform.translation(y = -y)
        elif axis == 'Z':
            offset_transform = transform.translation(z = -z)
        else:
            raise ValueError("%s illegal 'axis' parameter: %r" % 
                               (self.name, axis_param))
        transform_out = offset_transform.add(transform_in)
        return transform_out

